package cn.wolfcode.web.controller;

import cn.wolfcode.commno.JsonResult;
import cn.wolfcode.domain.Brand;
import cn.wolfcode.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("brands")
public class BrandController {
    @Autowired
    private IBrandService brandService;

    @GetMapping("/list")
    public JsonResult list(){
        List<Brand> brands = brandService.list();
        return JsonResult.success(brands);
    }
    //增加方法 带个增加的实体类
    @PostMapping("add")
    public JsonResult add(Brand brand){
        boolean save = brandService.save(brand);
        return JsonResult.success();
    }
    @PostMapping("update")
    public JsonResult update(Brand brand){
        brandService.updateById(brand);
        return JsonResult.success();
    }
    @GetMapping("delete")
    public JsonResult delete(Long id){
        brandService.removeById(id);
        return JsonResult.success();
    }
    @GetMapping ("detail")
    public JsonResult detail(Long id){
        Brand brand = brandService.getById(id);
        return JsonResult.success(brand);
    }


}
